function Game() {
    this.timePerDay = 1000; // 1000 ms
    this.day = 0;
    this.dayCounter = 0;
    this.pxPerDay = 40; // 600/15 = 40
    
    var d = new Date();
    this.time = d.getTime();
    this.time_started = this.time;
    this.started = true;
    this.ms = 0;
    this.paused = false;

    /* add your module here */
    this.draw = new Draw();
    this.logic = new Logic();
    this.ui = new UI();
    this.manager = new Manager();
    this.traits = new Traits();
    this.opportunities = new Opportunities();
    
    this.difficulty = 0.5;
    
    this.incrementDay = function(ms) {
        this.dayCounter += ms;
        if (this.dayCounter >= this.timePerDay) {
            this.day++;
            this.dayCounter = 0;
            this.updateDay(this.day);
            $('#daycounter').html(this.day);
        }
    }

    this.updateDashboard = function () {
        $("#moneyCounter").html(Math.floor(game.logic.person.money * 100) / 100);
        $("#happinessCounter").html(game.logic.person.happiness);
        $("#gpaCounter").html(game.logic.person.GPA);
    }
    /*  called by browser whenever possible */
    this.update = function (me) {
        if (me.started && !me.paused) {
            var now = new Date().getTime();
            me.ms = (now - (me.time || now));
            var delta = me.ms;
            me.time = now;
            me.incrementDay(me.ms);
            me.draw.update(me.ms);
            requestAnimationFrame(function () {
                me.update(me);
            });
        }
    }
    
    /* called at the start of each day */
    this.updateDay = function(day) {
        /* add calls to dailys here */
        this.manager.nextDay(day);
        this.updateDashboard();
    }

    this.checkState = function(){
        if (game.logic.person.money<0) {
            game.ui.win(false, 'you ran out of money');
        } else if (game.logic.person.happiness<0) {
            game.ui.win(false, 'you are super unhappy');
        } else if (game.logic.person.GPA<1) {
            game.ui.win(false, 'you got kicked out of college');
        }
    }
    
    this.pause = function() {
        this.paused = true;
    }
    
    this.unpause = function() {
        this.time = new Date().getTime();
        this.paused = false;
        this.update(this);
    }

    this.start = function () {
        /* call initializers here, before the update call */
        this.logic.init();
        this.manager.init();
        this.ui.init();
        this.updateDashboard();
        this.update(this);        
    }
}

$(document).ready(function () {
    window.requestAnimationFrame = window.requestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.msRequestAnimationFrame;
    game = new Game();
    game.start();
});